{% extends 'base.htm' %}
{% from 'macros.htm' import name_fmt, twitter_fmt, make_plural, history_checkin_fmt %}
{% set title = 'User Profile' %}

{% macro userlist(ulist) -%}
    {% set first = true %}
    {% for group in ulist.groups %}
	{% if group['items'] is iterable and group['items']|length > 0 %}
	    {% if first %}
		<hr>
		{% set first = false %}
	    {% endif %}
	    <p><b>{{ group.name }}:</b><br>
	    {% for user in group['items'] %}
		<a href="/user?userid={{ user.id|urlencode }}"><img class="usericon" src="{{ user.photo.prefix|e ~ '32x32' ~ user.photo.suffix|e }}"></a>
	    {% endfor %}
	{% endif %}
    {% endfor %}
{%- endmacro %}

{% block body %}

<p><img src="{{ user.photo.prefix|e ~ '36x36' ~ user.photo.suffix|e }}" class="usericon, lefticon" alt="">{{ name_fmt(user, button=false) }}<br>
{% if user.homeCity %}
    {{ user.homeCity|e }}<br>
{% endif %}
{% set contact = user.contact %}
{% if contact %}
    {% if contact.email %}
	<a href="mailto:{{ contact.email|urlencode }}">{{ contact.email|e }}</a><br>
    {% endif %}
    {% if contact.phone %}
	{% set phoneStr = contact.phone|phonefmt %}
	<a href="tel:{{ contact.phone|urlencode }}">{{ phoneStr|e }}</a><br>
    {% endif %}
    {{ twitter_fmt(contact.twitter) }}
    {% if contact.facebook %}
    	<a href="http://www.facebook.com/{{ contact.facebook|urlencode }}">Facebook</a>
    {% endif %}
{% endif %}

<br style="clear:both">

{% if user.bio %}
    {{ user.bio|e }}<br>
{% endif %}

{% set pageinfo = user.pageInfo %}
{% if pageinfo %}
    <p>
    <img src="{{ pageinfo.banner|e }}"><br>
    {{ pageinfo.description|e }}<br>
    {% if pageinfo.links and pageinfo.links['items'] is iterable %}
	{% for link in pageinfo.links['items'] %}
	    <a href="{{ link.url|e }}">{{ link.url|e }}</a><br>
	{% endfor %}
    {% endif %}
{% endif %}

{% if user.scores %}
    <p><b>Recent Stats</b><br>
    Points: {{ user.scores.recent|e }}<br>
    Max: {{ user.scores.max|e }}<br>
    Checkins: {{ user.scores.checkinsCount|e }}<br>
{% endif %}

<p>
{% if user.checkins %}
    {{ make_plural(user.checkins.count, 'checkin') }}<br>
{% endif %}
{% if user.photos %}
    {{ make_plural(user.photos.count, 'photo') }}<br>
{% endif %}
{% if user.friends %}
    {{ make_plural(user.friends.count, 'friend') }}<br>
{% endif %}
{% if user.following %}
    {{ make_plural(user.following.count, 'following') }}<br>
{% endif %}
{% if user.mayorships %}
    <a class="button" href="/mayor?userid={{ user.id|urlencode }}">{{ make_plural(user.mayorships.count, 'mayorship') }}</a><br>
{% endif %}
{% if user.badges %}
    <a class="button" href="/badges?userid={{ user.id|urlencode }}">{{ make_plural(user.badges.count, 'badge') }}</a><br>
{% endif %}
{% if user.tips %}
    {{ make_plural(user.tips.count, 'tip') }}<br>
{% endif %}

{% if user.checkins and user.checkins['items'] is iterable %}
    <hr>
    <p><b>Recent checkin:</b><br>
    {% for checkin in user.checkins['items'] %}
	{{ history_checkin_fmt(checkin, lat, lon) }}<br>
    {% endfor %}
{% endif %}

{% if user.friends and user.friends.groups is iterable %}
    {{ userlist(user.friends) }}
{% endif %}

{% if user.following and user.following.groups is iterable %}
    {{ userlist(user.following) }}
{% endif %}

{% if user.followers and user.followers.groups is iterable %}
    {{ userlist(user.followers) }}
{% endif %}

{% if user.photos and user.photos['items'] is iterable and user.photos['items']|length > 0 %}
    <hr><p><b>Recent Photos:</b><br>
    {% for photo in user.photos['items'] %}
	{% set photoparms = { 'photoid' : photo.id, 'userid' : user.id } %}
	<a href="/photo?{{ photoparms|urlparms }}"><img src="{{ photo.prefix|e ~ '100x100' ~ photo.suffix|e }}"></a>
    {% endfor %}
{% endif %}

{% endblock %}

{# vim:set ft=htmldjango tw=0: #}
